package com.nlp.word;

import java.util.HashMap;
import java.util.StringTokenizer;

public class WordCounter {

	public static void main(String[] args) {
		//单词和对应的次数
		HashMap<String, Integer> wordcount = new HashMap<String, Integer>();
		String inputStr = "this is a apple";
		StringTokenizer st = new StringTokenizer(inputStr);
		while(st.hasMoreTokens()) {//按空格分割
			String word = st.nextToken();
			Integer count = wordcount.get(word);
			if (count == null) {
				count = new Integer(0);
			}
			count = count+1;
			wordcount.put(word, count);
		}
		System.out.println(wordcount);
	}
}
